<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
</head>
<body>
<form class="x-so" action="/manager-manager/managerlist" id="myform" >
    <select id="condition" name="condition" style="width: 110px;height: 37px">
        <option value="----">----</option>
        <option value="经理编号">经理编号</option>
        <option value="姓名">姓名</option>
    </select>
    <input class="layui-input" name="conValue" type="text" id="conValue" placeholder="请输入查询条件">
    <input type="submit" class="layui-btn layui-btn-normal" value="查询" >
    <button class="layui-btn layui-btn-normal" type="button" onclick="add()">添加信息</button>
    <a id="dlink"  style="display:none;"></a>
    <input type="button" class="layui-btn layui-btn-normal" onclick="tableToExcel('tables', 'name', '经理表.xls')" value="导出">
</form>
<table class="layui-table" id="tables" lay-size="sm">
    <thead>
    <th>经理编号</th>
    <th>姓名</th>
    <th>昵称</th>
    <th>密码</th>
    <th>性别</th>
    <th>出生日期</th>
    <th>联系电话</th>
    <th>邮箱地址</th>
    <th>学历</th>
    <th>身份证号码</th>
    <th>权限等级</th>
    <th>备注</th>
    <th>操作</th>
    </thead>
    <tbody>
    <tr th:each="i:${qaq.list}">
        <td th:text="${i.managerId}"></td>
        <td th:text="${i.managerName}"></td>
        <td th:text="${i.managerNickName}"></td>
        <td th:text="${i.managerPwd}"></td>
        <td th:text="${i.managerSex}"></td>
        <td th:text="${i.managerBirth}"></td>
        <td th:text="${i.managerTel}"></td>
        <td th:text="${i.managerEmail}"></td>
        <td th:text="${i.managerEdu}"></td>
        <td th:text="${i.managerIdCard}"></td>
        <td th:text="${i.managerRightLevel}"></td>
        <td th:text="${i.managerText}"></td>

        <td>
            <button class="layui-btn layui-btn-normal" type="button" onclick="update(this)">修改</button>
            <button class="layui-btn layui-btn-normal" type="button" onclick="delUser(this)">删除</button>
        </td>
    </tr>
    </tbody>
</table>
<div style="position: absolute;left: 30%">
    <a class="layui-btn layui-btn-normal" th:href="@{/manager-manager/managerlist(page=${qaq.pre})}" >上一页</a>
    <a class="layui-btn layui-btn-normal" th:href="@{/manager-manager/managerlist(page=${qaq.next})}" >下一页</a>
    一共有<span th:text="${qaq.total}"></span>条数据
    一共有<span th:text="${qaq.totalPage}"></span>页
    当前第<span th:text="${qaq.cur}"></span>页
</div>

</body>
</html>
<script>
    function update(obj) {
        //获取当前选中行的userId的值
        var id =$(obj).parent().parent().find("td").eq(0).text();
        //打开弹窗
        x_admin_show("修改","/manager-manager/managereditPage?managerId="+id,500,600)

    }
    //添加信息
    function add() {
        x_admin_show("新建信息","/manager-manager/addPage",500,600)

    }

    //删除
    function delUser(obj){
        //获取当前选中行的managerId值
        var id = $(obj).parent().parent().find("td").eq(0).text();
        //用提示框确定用户是否删除
        layer.confirm("你确定要删除吗?",{icon:3,title:"警告"},function(index){
            $.ajax({
                url:"/manager-manager/managerdel",
                type:"get",
                data:{"managerId":id},
                dataType:"json",
                success:function(data){
                    layer.alert(data.info,function(){
                        parent.window.location.href=parent.window.location.href;
                    })
                    /*          if(data.info=="删除成功"){
                                  // 第一种：刷新
                                  //parent.window.location.href=parent.window.location.href;
                                  //第二种：刷新
                                  $(obj).parent().parent().remove();
                              }*/
                    //关闭
                    layer.close(index);
                }
            })

        })
    }
    //excle导出
    var tableToExcel = (function () {
        var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>',
            base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) },
            format = function (s, c) { return s.replace(/{(\w+)}/g, function (m, p) { return c[p]; }) };
        return function (table, name, filename) {
            if (!table.nodeType) table = document.getElementById(table)
            var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }

            document.getElementById("dlink").href = uri + base64(format(template, ctx));
            document.getElementById("dlink").download = filename;
            document.getElementById("dlink").click();
        }
    })()
</script>